package com.uncc.sensingsuite;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
 
public class mainlist extends Activity {
 
	private ArrayList<String> groups;
	private ArrayList<ArrayList<ArrayList<String>>> childs;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        setContentView(R.layout.mainlist);
 
        ExpandableListView l = (ExpandableListView) findViewById(R.id.ExpandableListView01);
 
        loadData();
 
        myExpandableAdapter adapter = new myExpandableAdapter(this, groups, childs);
		l.setAdapter(adapter);
    }
 
    public class myExpandableAdapter extends BaseExpandableListAdapter 
    {
 
    	private ArrayList<String> groups;
        private ArrayList<ArrayList<ArrayList<String>>> children;
 
    	private Context context;
 
    	public myExpandableAdapter(Context context, ArrayList<String> groups, ArrayList<ArrayList<ArrayList<String>>> children)
    	{
            this.context = context;
            this.groups = groups;
            this.children = childs;
        }
 
 
    	@Override
        public boolean areAllItemsEnabled()
        {
            return true;
        }
 
 
        @Override
        public ArrayList<String> getChild(int groupPosition, int childPosition) 
        {
            return children.get(groupPosition).get(childPosition);
        }
 
        @Override
        public long getChildId(int groupPosition, int childPosition) 
        {
            return childPosition;
        }
 
 
        @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,View convertView, ViewGroup parent) 
        {
        	String child = (String) ((ArrayList<String>)getChild(groupPosition, childPosition)).get(0);
 
            if (convertView == null) 
            {
                LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.expandablelistview_child, null);
            }
 
            TextView childtxt = (TextView) convertView.findViewById(R.id.TextViewChild);
            
            childtxt.setText(child);
 
            return convertView;
        }
 
        @Override
        public int getChildrenCount(int groupPosition) 
        {
            return children.get(groupPosition).size();
        }
 
        @Override
        public String getGroup(int groupPosition) 
        {
            return groups.get(groupPosition);
        }
 
        @Override
        public int getGroupCount() 
        {
            return groups.size();
        }
 
        @Override
        public long getGroupId(int groupPosition) 
        {
            return groupPosition;
        }
 
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) 
        {
         	String group = (String) getGroup(groupPosition);
 
        	if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.expandablelistview_group, null);
            }
 
            TextView grouptxt = (TextView) convertView.findViewById(R.id.TextViewGroup);
 
            grouptxt.setText(group);
 
            return convertView;
        }
 
        @Override
        public boolean hasStableIds() 
        {
            return true;
        }
 
        @Override
        public boolean isChildSelectable(int arg0, int arg1) 
        {
            return true;
        }
 
    }
 
    private void loadData()
    {
    	groups= new ArrayList<String>();
    	childs= new ArrayList<ArrayList<ArrayList<String>>>();
 
    	groups.add("Green");
        groups.add("Yellow Clockwise");
        groups.add("Yellow Counter Clockwise");
        groups.add("Red");
 
        childs.add(new ArrayList<ArrayList<String>>());
        childs.get(0).add(new ArrayList<String>());
        childs.get(0).get(0).add("Regal Starlight Cinema 14");
        childs.get(0).add(new ArrayList<String>());
        childs.get(0).get(1).add("Craver Croft");
        childs.get(0).add(new ArrayList<String>());
        childs.get(0).get(2).add("Facilities Management/ Police and public safety");
        childs.get(0).add(new ArrayList<String>());
        childs.get(0).get(3).add("3");
        childs.get(0).add(new ArrayList<String>());
        childs.get(0).get(4).add("4");
        childs.get(0).add(new ArrayList<String>());
        childs.get(0).get(5).add("5");
        childs.get(0).add(new ArrayList<String>());
        childs.get(0).get(6).add("6");
 
        childs.add(new ArrayList<ArrayList<String>>());
        childs.get(1).add(new ArrayList<String>());
        childs.get(1).get(0).add("Child 1 group 2");
        childs.get(1).add(new ArrayList<String>());
        childs.get(1).get(1).add("Child 2 group 2");
        childs.get(1).add(new ArrayList<String>());
        childs.get(1).get(2).add("Child 3 group 2");
 
        childs.add(new ArrayList<ArrayList<String>>());
        childs.get(2).add(new ArrayList<String>());
        childs.get(2).get(0).add("Child 1 group 3");
        childs.get(2).add(new ArrayList<String>());
        childs.get(2).get(1).add("Child 2 group 3");
        childs.get(2).add(new ArrayList<String>());
        childs.get(2).get(2).add("Child 3 group 3");
        
        //Red Bus
        childs.add(new ArrayList<ArrayList<String>>());
        childs.get(3).add(new ArrayList<String>());
        childs.get(3).get(0).add("Regal Starlight Cinema 14");
        childs.get(3).add(new ArrayList<String>());
        childs.get(3).get(1).add("Craver Croft");
        childs.get(3).add(new ArrayList<String>());
        childs.get(3).get(2).add("Facilities Management/ Police and public safety");
        childs.get(3).add(new ArrayList<String>());
        childs.get(3).get(3).add("3");
        childs.get(3).add(new ArrayList<String>());
        childs.get(3).get(4).add("4");
        childs.get(3).add(new ArrayList<String>());
        childs.get(3).get(5).add("5");
        childs.get(3).add(new ArrayList<String>());
        childs.get(3).get(6).add("6");
    }
}